
#目标服务器类型  
#麒麟服务器  gcc 5.4
Kylin_gcc54 = 0
#centos gcc 5.4 
centos_54 = 0

#自动识别目标平台
SYSPLATFORMINFO := $(shell cat /proc/version)
SYSPLATFORMGCC  := $(shell gcc --version)

ifeq "$(shell arch)" "aarch64"
Kylin_gcc54 = 1
DST_PLATFORM_DEF_DIR = dep-Kylin-gcc54
else
ifeq "$(shell arch)" "x86_64"
centos_54 = 1
DST_PLATFORM_DEF_DIR = dep-centos-gcc54
else
$(error 目标平台系统错误)
endif
endif

SHARE=-shared
TARGET=libslbasetool.so

sltoolSrcDir=../sl_tool
SLAsynFrameSrcDir = ../sl_asyn_frame
SLNetSrcDir = ../sl_net
SLAIGJsonSrcDir = ../AIGCJson
SLNetFrameSrcDir = ../sl_net_frame

CFLAGS=-g -O0 -Wall -fstack-protector-all -Wno-unused -fPIC -D__LINUX__ -D_DEBUG -std=c++11  -fvisibility=hidden
LINK:=-rdynamic -levent -levent_core -levent_extra -levent_pthreads -lpthread 
LINKDIR = -Wl,-rpath=.
INCLUDES=-I$(sltoolSrcDir) -I$(SLAsynFrameSrcDir) -I$(SLNetSrcDir)

ifeq ($(Kylin_gcc54),1)
INCLUDES += -Ilibevent2_1-Kylin-gcc54/include -I../
LINKDIR  += -Llibevent2_1-Kylin-gcc54/lib
endif

ifeq ($(centos_54),1)
INCLUDES += -Ilibevent/include -I../
LINKDIR  += -Llibevent/lib
endif
 

TARGET_CPPS= $(sltoolSrcDir)/SLT_memory.cpp \
	 $(sltoolSrcDir)/SLT_thread_pool.cpp \
	 $(sltoolSrcDir)/SLT_timer.cpp \
	 $(sltoolSrcDir)/SLT_timer_imp.cpp \
	 $(sltoolSrcDir)/SLT_uuid.cpp \
	 $(sltoolSrcDir)/SLT_log.cpp \
	 $(sltoolSrcDir)/SLT_logImpl.cpp \
	 $(sltoolSrcDir)/SLT_resendList.cpp \
	 $(sltoolSrcDir)/SLT_rwlock.cpp \
	 $(sltoolSrcDir)/SLT_filesystem.cpp \
	 $(SLAsynFrameSrcDir)/SL_asynFrame.cpp \
	 $(SLAsynFrameSrcDir)/SL_asynFrameImp.cpp \
	 $(SLNetSrcDir)/SL_net.cpp \
	 $(SLNetSrcDir)/SL_tcpServer.cpp \
	 $(SLNetFrameSrcDir)/SLT_tcpSender.cpp \
	 $(SLNetFrameSrcDir)/SLT_tcpSenderImpl.cpp \
	 $(SLNetFrameSrcDir)/SLT_tcpServerImpl.cpp \
	 $(SLNetSrcDir)/SL_tcpServer_event_impl.cpp \
	 $(SLNetSrcDir)/SL_tcpClient_event_impl.cpp


#$(SLNetSrcDir)/SL_tcpClient_impl.cpp \
#$(SLNetSrcDir)/SL_tcpServer_epoll_impl.cpp \
	 	 
TARGET_OBJS=$(TARGET_CPPS:.cpp=.o)

${TARGET}:${TARGET_OBJS}
	$(CXX) $(SHARE) -o $@ $^ $(LINKDIR) ${LINK}

%.o:%.cpp
	$(CXX) -c  $(CFLAGS) $(INCLUDES)  -o $@ $<



#安装内容，准备发布
include_dst_dir=include
bin_dst_dir=lib

.PHONY: install
install:
	-rm -rf $(bin_dst_dir)
	-rm -rf $(include_dst_dir)
	-mkdir $(bin_dst_dir)
	-mkdir $(include_dst_dir)

	#$(shell if [ ! -d "$(include_dst_dir)" ];then mkdir $(include_dst_dir);fi)
	#$(shell if [ ! -d "$(bin_dst_dir)" ];then mkdir $(bin_dst_dir);fi)
	
	cp $(sltoolSrcDir)/SLT_log.h  	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_memory.h  	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_resendList.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_thread_pool.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_timer.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_tool_pub.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_tool_pub_def.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_uuid.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_rwlock.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_smartEmbedPtr.h 	$(include_dst_dir)/
	cp $(sltoolSrcDir)/SLT_filesystem.h      $(include_dst_dir)/
	
	cp $(SLAsynFrameSrcDir)/SL_asynFrame.h 	$(include_dst_dir)/
	cp $(SLAsynFrameSrcDir)/SL_asynFramePub.h 	$(include_dst_dir)/
	
	cp $(SLNetSrcDir)/SL_net.h  	    $(include_dst_dir)/
	cp $(SLNetSrcDir)/SL_tcpServer.h  	$(include_dst_dir)/
	cp $(SLNetSrcDir)/SL_tcpClient.h  	$(include_dst_dir)/

	cp $(SLNetFrameSrcDir)/SLT_csConnect.h  	$(include_dst_dir)/
	cp $(SLNetFrameSrcDir)/SLT_tcpSender.h  	$(include_dst_dir)/
	
	cp -r $(SLAIGJsonSrcDir)    $(include_dst_dir)/

	#
	cp  libslbasetool.so  $(bin_dst_dir)/
	cp  ../config/config_log.ini     $(bin_dst_dir)/


test_bin_dir=./test_bin
test_src_dir = ../test
TESTTARGET_CPPS= $(test_src_dir)/slbasetooltest.cpp \
			$(test_src_dir)/SLTool_asynframe_test.cpp \
			$(test_src_dir)/SLTool_log_test.cpp \
			$(test_src_dir)/SLTool_net_test.cpp \
			$(test_src_dir)/SLTool_timer_test.cpp

test_Include= -I../ -I../sl_tool -I../sl_net -I../sl_asyn_frame -I../sl_net_frame
test_link=	-Wl,-rpath=. -lpthread -L./ -lslbasetool			 

TESTTARGET_OBJS=$(TESTTARGET_CPPS:.cpp=.ot)

%.ot:%.cpp
	$(CXX) -c  $(CFLAGS) $(test_Include)  -o $@ $<

test:${TESTTARGET_OBJS}
	$(CXX) -o $@ $^ $(test_link)
	$(shell if [ ! -d "$(test_bin_dir)" ];then mkdir $(test_bin_dir);fi)
	cp -f $@ ${test_bin_dir}
	cp -f libslbasetool.so ${test_bin_dir}



.PHONY: clean
clean:
	-rm -rf $(TARGET_OBJS)
	-rm -rf $(TESTTARGET_OBJS)